package com.example.fw;

import java.util.List;
import static org.openqa.selenium.support.ui.ExpectedConditions.*;


import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;

public abstract class HelperBase {
        private WebDriverWait wait;
        protected ApplicationManager manager;
        protected WebDriver driver;

                
        public HelperBase(ApplicationManager manager) {
                this.manager = manager;
                this.driver = manager.driver;
                
        }
        
        public boolean isElementPresent(By by) {
                try {
                        driver.findElement(by);
                        return true;
                } catch (NoSuchElementException e) {
                        return false;
                }
        }

        protected void type(By locator, String text) {
                if (text != null) {
                        driver.findElement(locator).clear();
                        driver.findElement(locator).sendKeys(text);     
                }
        }

        protected void click(By locator) {
                driver.findElement(locator).click();
        }
        
        protected void selectByText(By locator, String text) {
                if (text != null) {
                        new Select(driver.findElement(locator)).selectByVisibleText(text);
                }
                
        }
    
        protected void selectByNumber(By locator, int index) {
                if (index != 0) {
                        new Select(driver.findElement(locator)).selectByIndex(index);
                }
                
        }
        protected List<WebElement> getElements(By locator) {

        wait.until(visibilityOfElementLocated(locator));

        List<WebElement> elements = driver.findElements(locator);

        return elements;

}



}